﻿using Microsoft.Build.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Rhino.Mocks;

namespace KubertSoft.MSBuildTasks.Subversion.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class SvnTaskBaseTests
    {
        /// <summary>
        /// A repository of mocks.
        /// </summary>
        private MockRepository _mocks;

        /// <summary>
        /// A mock that represents build engine.
        /// </summary>
        private IBuildEngine _buildEngine;

        private TaskItemDictionary _inputItems;
        private TaskItemDictionary _outputItems;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        /// <summary>
        /// Initializes the mocks.
        /// </summary>
        [TestInitialize]
        public void InitializeMocks()
        {
            _mocks = new MockRepository();

            _buildEngine = _mocks.PartialMock<BuildEngineStub>();
            _inputItems = _mocks.StrictMock<TaskItemDictionary>();
            _outputItems = _mocks.StrictMock<TaskItemDictionary>();
        }

        /// <summary>
        /// Cleans mocks.
        /// </summary>
        [TestCleanup]
        public void CleanUpMocks()
        {
            _mocks.VerifyAll();
        }

        [TestMethod]
        public void TestGeneralExecution()
        {
            var task = _mocks.PartialMock<SvnTaskBaseStub>();
            task.InputTaskItems = _inputItems;
            task.OutputTaskItems = _outputItems;

            using (_mocks.Ordered())
            {
                task.Expect(x => x.InitializeInputParameters());
                task.Expect(x => x.InitializeOutputParameters());
            }

            _mocks.ReplayAll();

            task.BuildEngine = _buildEngine;
            task.Execute();

            Assert.AreEqual(0, task.ExitCode);
        }
    }
}
